<template>
	<view class="wrap">
		<view class="list flex" v-if="list.length === 0">
			<view class="width-75 left">
				<i-icon icon="iconyinhangka" type="single" size="32rpx" color="#FBD220"></i-icon>
				<text class="pl-10">暂未添加对公账户</text>
			</view>
			<view class="width-25 text-right">
				<view class="addbtn" @click="addAccount">
					<i-icon icon="icontianjia_1" type="single" size="30rpx" color="#333"></i-icon>
					<text class="pl-10 font-26 color-333">添加</text>
				</view>
			</view>
		</view>
		<view class=""  v-else>
			<!-- -->
			<view class="mt-20" >
				<view class="cell flex" v-for="(it, i) in list" :key="i">
					<view class="width-10 left pad-t-b-20 line40"><i-icon icon="iconyinhangka" type="single" size="32rpx" color="#FBD220"></i-icon></view>
					<view class="width-90 text-right">
						<view class="pad-t-b-5 font-30 color-333">{{ it.name }}</view>
						<view class="pad-t-b-5 font-26 color-999">尾号{{ it.num }}储蓄卡</view>
					</view>
				</view>
			</view>
			<view class="mt-20">
				<view class="cell">
					<view class="width-100">
						<view class="font-28 color-333">提现金额</view>
						<view class="font-20 color-999 mt-10">我们会扣除提现金额的0.006%，作为手续费</view>
					</view>
					<view class="width-100 flex mt-20 border-bottom-1">
						<view class="width-10 font-48">￥</view>
						<view class="width-90"><u-input type="number" v-model="cash" placeholder="0" placeholderStyle="color:'#333'"></u-input></view>
					</view>
					<view class="width-100 flex mt-20">
						<view class="width-50 font-26 color-666" ><text v-if="balance>=0">可用余额{{balance>0?balance:0}}元</text><text style="color: red;" v-else>超出可用余额</text></view>
						<view class="width-50 font-26 color-FBB000 u-text-right" @click="cash=totalmoney,balance=totalmoney-cash">全部提现</view>
					</view>
				</view>
			</view>
			
			<view class="width-80 btn-bg-yellow" @click="Cash">确认提现</view>
				
		</view>
		
		<u-popup
			v-model="codeshow"
			mode="center"
			border-radius="20"
			width="570rpx"
			height="350rpx"
			:mask-close-able="false"
			close-icon="close-circle"
			close-icon-size="40"
			:closeable="true"
			@close="closePopup"
		>
			<view class="font-34 font-bold mt-40 u-text-center">输入支付密码</view>

			<u-message-input
				class="mt-20"
				:dot-fill="true"
				:maxlength="6"
				:value="code"
				width="70"
				active-color="#FBB000"
				mode="bottomLine"
				:bold="false"
				:focus="true"
				@finish="finishCode"
			></u-message-input>
		</u-popup>
		<u-toast ref="uToast" />
	</view>
</template>

<script>
export default {
	data() {
		return {
			list: [],
			code: '',
			codeshow: false,
			cash: null,
			totalmoney:'',
			balance:0
		};
	},
	watch:{
		cash(val){
			// if(this.balance>0){
				this.balance=this.totalmoney-val
			
		},
	},
	created() {
		this.getBankCardList();
	},
	onLoad(options) {
		this.totalmoney=options.total
		this.balance=options.total
		console.log(this.$store.state.userInfoDetail.store.storeId);
	},
	methods: {
		//添加账户
		addAccount() {
			uni.navigateTo({
				url: '/pages_common/pages_me/assets/addAccount/addAccount'
			});
		},
		Cash() {
			if(this.cash>=1){
				this.codeshow = true;
			}else{
				uni.showToast({
				    title: '提现金额至少为1块',
				    duration: 2000,
						icon:'none'
				});
			}
			
		},
		getBankCardList() {
			this.$api.user
				.getBankCardList({
					pageIndex: 1,
					pageSize: 100
				})
				.then(res => {
					if (res.data.total !== 0) {
						this.list = res.data.list;
						// this.total = res.data.total
					}
				})
				.catch(e => {
					console.log(e);
				});
		},
		// 确认提现
		finishCode(e) {
			console.log(this.cash);
			console.log(this.$store.state);
			let _this=this
			this.$api.bindbank
				.ApplyWithdraw({
					platform: 1,
					StoreId:this.$store.state.userInfoDetail.store.storeId,
					accountId:this.$store.state.tid ,
					applyWithdrawMoney:Number(this.cash) ,
					payPassword: e
				})
				.then(res => {
				
					if(res.data){
					// uni.showToast({
					//     title: '申请成功，提现金额会在三个工作日到账！',
					//     duration: 2000,
					// 		icon:'success'
					// });
					_this.$refs.uToast.show({
										title: '申请成功，提现金额会在三个工作日到账！',
										type: 'success',
										duration: 2000
									})
					setTimeout(()=>{
						uni.redirectTo({
						    url: '/pages_common/pages_me/assets/assetsManage/assetsManage'
						});
					},2000)
						
					}
				
					console.log(res);
				})
				.catch(e => {
					console.log(e);
				});
		},
		closePopup() {
			this.codeshow = false;
		}
	}
};
</script>

<style scoped lang="scss">
.wrap {
	width: 100%;
	min-height: 100vh;
	background: #f6f6f6;
	padding-top: 20rpx;
}
.list,
.cell {
	width: 94%;
	margin: auto;
	padding: 40rpx 20rpx;
	background: #fff;
	border-radius: 10rpx;
	.left {
		font-size: 30rpx;
		color: #999999;
		line-height: 44rpx;
	}
	.addbtn {
		width: 140rpx;
		height: 54rpx;
		line-height: 54rpx;
		background: linear-gradient(-90deg, #fdd421, #ffe23e);
		border-radius: 27rpx;
		text-align: center;
	}
}
.cell {
	padding: 20rpx 20rpx;
}
.pad-t-b-5 {
	padding: 10rpx 0rpx;
}
.line40 {
	line-height: 80rpx !important;
}
.font-20 {
	font-size: 20rpx;
}
.font-48 {
	font-size: 48rpx;
	color: #333;
	font-weight: bold;
}
.width-80 {
	margin: 10%;
	height: 90rpx;
	line-height: 90rpx;
	font-size: 32rpx;
	margin-top: 200rpx;
}
.mt-40 {
	margin-top: 60rpx;
}
</style>
